//
//  HomeSectionTwo.m
//  JiaoX
//
//  Created by yinqy on 15/1/29.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//  首页第2项，右边为大图，左边为两个小图

#import "HomeSectionTwo.h"
#import "LeftLineView.h"
#import "HomeBanner.h"
#import "HomeFirstPageHeaderView.h"

#define TITLE_FONT_SIZE [DimensUtils getScaleX:14]

@interface HomeSectionTwo()
{
    UIButton *_leftBtn;
    UIButton *_rightBtn1;
    UIButton *_rightBtn2;
    
    HomeBannerList *_bannerList;
}

@end

@implementation HomeSectionTwo
- (instancetype)initWithHomeBannerList:(HomeBannerList *)bannerList{
    self = [super init];
    if (self) {
        _bannerList = bannerList;
        [self setBackgroundColor:[UIColor whiteColor]];
        LeftLineView *title = [[LeftLineView alloc]initWithTitleFontSize:TITLE_FONT_SIZE];
        [title setText:bannerList.title];
        title.label.textColor = JXColor(51, 51, 51);
        title.x = JXPublicInset;
        title.y = JXPublicInset;
        
        
        [self addSubview:title];
        CGFloat leftBtnHeight = (JXScreenW-3*JXPublicInset)/2;
        _leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(JXPublicInset, CGRectGetMaxY(title.frame)+JXPublicInset, leftBtnHeight, leftBtnHeight)];
        [_leftBtn setTag:0];
        [_leftBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_leftBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:((HomeBanner *)bannerList.list[0]).bannerImg] forState:UIControlStateNormal];
        [self addSubview:_leftBtn];
        
        
        _rightBtn1 = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_leftBtn.frame)+JXPublicInset, _leftBtn.y, _leftBtn.width, (_leftBtn.height-JXPublicInset)*0.5)];
        [_rightBtn1 setTag:1];
        [_rightBtn1 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_rightBtn1 sd_setBackgroundImageWithURL:[NSURL URLWithString:((HomeBanner *)bannerList.list[1]).bannerImg] forState:UIControlStateNormal];
        [self addSubview:_rightBtn1];
        
        _rightBtn2 = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_leftBtn.frame)+JXPublicInset, CGRectGetMaxY(_rightBtn1.frame)+JXPublicInset, _leftBtn.width, (_leftBtn.height-JXPublicInset)*0.5)];
        [_rightBtn2 setTag:2];
        [_rightBtn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_rightBtn2 sd_setBackgroundImageWithURL:[NSURL URLWithString:((HomeBanner *)bannerList.list[2]).bannerImg] forState:UIControlStateNormal];
        [self addSubview:_rightBtn2];
        
        [self setSize:CGSizeMake(JXScreenW, CGRectGetMaxY(_leftBtn.frame)+JXPublicInset)];
    }
    return self;
}
-(void)btnClick:(UIButton *)btn{
    HomeBanner *banner = _bannerList.list[btn.tag];
    if ([self.superview isKindOfClass:[HomeFirstPageHeaderView class]]) {
        HomeFirstPageHeaderView *view  =(HomeFirstPageHeaderView *) self.superview;
        if ([view.delegate respondsToSelector:@selector(sectionTwoClick:)]) {
            [view.delegate sectionTwoClick:banner.url];
        }
    }
}

@end
